/**
 * @Description: 用户信息处理
 * @Author: wrysunny
 * @Date: 2024-11-18 17:55:00
 * @LastEditor: wrysunny
 * @LastEditTime: 2024-11-21 13:36:06
 */
import {
	bindPhone,
	getUserInfo,
	updateUserInfo
} from '../config/api/user';
import utils from '../utils/utils';
import {
	useLoginStore
} from '@/store/login';
const useUserInfo = () => {
	const store = useLoginStore();
	// 获取用户信息
	const getUserInfoFn = async () => {
		try {
			const res = await getUserInfo();
			store.userInfo = res.data;
		} catch (e) {
			//TODO handle the exception
		}
	};
	// 修改用户信息
	const updateUserInfoFn = async () => {
		try {
			const res = await updateUserInfo(store.userInfo);
			if (res.code == 200) {
				utils.showToast("修改成功")
			}
		} catch (e) {
			//TODO handle the exception
		}
	}
	//绑定手机号
	const bindPhoneFn = async () => {
		try {
			const res = await bindPhone({
				phone: store.userInfo.phone
			});
			if (res.code == 200) {
				utils.showToast("绑定成功")
			}
		} catch (e) {
			//TODO handle the exception
		}
	}
	const loginOut = async () => {
		await utils.showModal("确认退出登录？")
		store.loginOut()
	}
	return {
		getUserInfoFn,
		updateUserInfoFn,
		bindPhoneFn,
		loginOut
	}
}
export default useUserInfo